<?php
include 'lib/user.php';
include 'lib/member.php';
include 'config/config.php';

$config=new config();
$config->connect();

if(isset($_POST["MM_login"])){
	if($_POST["email"]=="" || $_POST["password"]=="" ){
		echo "<script>alert('Silahkan isikan Email dan Password terlebih dahulu!');</script>";}
		else {
				$user = new User();
				$user->email=$_POST["email"];
				$user->password=$_POST["password"];
				$User_Dao=new User_Dao();
				if($User_Dao->cek_user($user)==false){
					echo"<script>alert('Email dan Password tidak sesuai!');</script>";
				}
				if($User_Dao->cek_user($user)==true){
					$nama=$User_Dao->get_ByEmail($user->email);   //menyimpan array user berdasarkan parameter email
					if($nama->role=="admin"){
						//echo '1';
						session_start();
						$_SESSION['MM_Username'] = "admin";
						$_SESSION['MM_Id'] = $nama->id;
						$togo="admin/beranda_admin.php";
						header ("Location:$togo");
					}
				
					if($nama->role=="member"){
						//echo '2';
						$Member_Dao=new Member_Dao();
						$member=$Member_Dao->get_id($nama->id);
						if($member->banned==0){
							session_start();
							$_SESSION['MM_Username'] = $member->nama;
							$_SESSION['MM_Id'] = $member->id;
							$_SESSION['MM_Email'] = $email;
							$togo="member/beranda_member.php";
							header ("Location:$togo");
						}
						
					}
				} 
	}
}	
?>
<?php include("header.php") ?>
<?php include("menu_kiri.php") ?>

<div id="body">
<div class="topbox">
		Silahkan Login sesuai dengan hak akses anda
		  <form id="login" name="form" method="post" action="login.php">
		<table align="center" >
		<tr>
		<td>Email </td>
		<td> : </td>
		<td><input type="text" name="email" value="" size=32 /></td>
	  </td>
		</tr>
	
	<tr>
		<td>Password </td>
		<td> : </td>
		<td><input type="password" name="password" value="" size=32/></td>
	</tr>
	
	<tr>
		<td></td>
		<td></td>
		<td><div align="right"><input type="submit" name="Submit" value="Submit" id="Submit"></div></td>
	</tr>
</table>
<input type="hidden" name="MM_login" value="login">
</form> 

<div class="right"><a href="reset_password.php">Lupa Password?</a></div>

                  
	                  
</div>             
</div>
          
         <div class="clear"></div>
         <?php include("footer.php") ?>
		